from django.db import models

from hotels.models import Hotel
from django.contrib.auth.models import User

# Create your models here.

class EnumField(models.Field):
    def __init__(self, *args, **kwargs):
        super(EnumField, self).__init__(*args, **kwargs)
        assert self.choices, "Need choices for enumeration"

    def db_type(self, connection):
        if not all(isinstance(col, basestring) for col, _ in self.choices):
            raise ValueError("MySQL ENUM values should be strings")
        return "ENUM({})".format(','.join("'{}'".format(col) 
                                          for col, _ in self.choices))

class RateNum(EnumField, models.CharField):
    def __init__(self, *args, **kwargs):
        rate_num = [('0', '0'),
                   ('1', '1'),
                   ('2', '2'),
                   ('3', '3'),
                   ('4', '4'),
                   ('5', '5'),
                   ('6', '6'),
                   ('7', '7'),
                   ('8', '8'),
                   ('9', '9'),
                   ('10', '10'),
                  ]
        super(RateNum, self).__init__(*args, choices=rate_num, **kwargs)



class Rate(models.Model):
	"""docstring for Rate"""
	user_id = models.ForeignKey(User)
	hotel_id = models.ForeignKey(Hotel)
	title = models.CharField(max_length=100)
	body = models.TextField()
	rate = RateNum(max_length=2)
		
